#if !__ARM_PCS_VFP
#include <fenv.h>
#include <features.h>
#include <stddef.h>

#define LOS_FPU_MASK_NZCV                          0xf0000000
#define LOS_FPU_RESERVED                           0x00086060
#define LOS_FPU_DEFAULT                            0x00000000
#define LOS_FPU_DEFAULT_AND_EXCEPTIONS             (LOS_FPU_DEFAULT | 0x00001f00)

static inline unsigned long get_fpscr(void)
{
    unsigned long fpc;
    __asm__ __volatile__ ("vmrs %0, fpscr" : "=r" (fpc));
    return fpc;
}

static inline void set_fpscr(unsigned long fpc)
{
    __asm__ __volatile__ ("vmsr fpscr, %0" : : "r" (fpc));
}

int feclearexcept(int mask)
{
    return 0;
}

int feraiseexcept(int mask)
{
    return 0;
}

int fetestexcept(int mask)
{
    return 0;
}

int fegetround(void)
{
    return FE_TONEAREST;
}

hidden int __fesetround(int r)
{
    return 0;
}

int fegetenv(fenv_t *envp)
{
    return 0;
}

int fesetenv(const fenv_t *envp)
{
    if (envp == NULL) {
        return -1;
    }

    fexcept_t currFpscr = get_fpscr();
    fexcept_t newFpscr;
    fexcept_t updatedFpscr;
    if (envp != FE_DFL_ENV) {
        newFpscr = envp->__cw;
        if (((currFpscr ^ newFpscr) & ~LOS_FPU_MASK_NZCV) != 0) {
            set_fpscr(newFpscr);
        }
        return 0;
    }

    newFpscr = currFpscr & LOS_FPU_RESERVED;
    if (envp == FE_DFL_ENV) {
        newFpscr |= LOS_FPU_DEFAULT;
    } else {
        newFpscr |= LOS_FPU_DEFAULT_AND_EXCEPTIONS;
    }
    if (((newFpscr ^ currFpscr) & ~LOS_FPU_MASK_NZCV) != 0) {
        set_fpscr(newFpscr);
        updatedFpscr = get_fpscr();
        return newFpscr & ~updatedFpscr;
    }

    return 0;
}
#endif
